<template>
  <div class="app-container">
      <div class="filter-container">
        <el-input clearable v-model="search.name" placeholder="教师名字" style="width: 170px;"></el-input>
        <el-input clearable v-model="search.shopName" placeholder="所属机构" style="width: 170px;margin-left:5px;"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe 
      style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="10%" align="center" label="图片">
        <template slot-scope="scope">
          <span>
            <!-- <bx-image :src="scope.row.imageConvert"  :width="50" :height="50" :show-delete="false"></bx-image>  -->
            <el-image style="width: 50px; height: 50px" :src="scope.row.imageConvert" :preview-src-list="scope.row.imageConvertLarge"></el-image>
          </span>
        </template>
      </el-table-column>

      <el-table-column  min-width="10%" align="center" label="名字">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="10%" align="center" label="所属机构">
        <template slot-scope="scope">
          <span>{{ scope.row.shopName }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="10%" label="教学经验">
        <template slot-scope="scope">
            <span>{{scope.row.teachExp}}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="10%" label="教学科目">
        <template slot-scope="scope">
            <span>{{scope.row.subject}}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="20%" label="简介">
        <template slot-scope="scope">
            <span :title="scope.row.introduce">{{scope.row.introduce | filterLongText}}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="20%" label="教学成果">
        <template slot-scope="scope">
            <span>{{scope.row.achievement | filterLongText}}</span>
        </template>
      </el-table-column>
      
      <el-table-column  min-width="10%" align="center" label="时间">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作"  min-width="20%">
        <template slot-scope="scope">
          <router-link :to="'/shopmanage/techerdetails/'+scope.row.id">
            <el-button type="primary" size="small" icon="el-icon-edit">
              编辑
            </el-button>
          </router-link>
          <!-- <el-popconfirm title="确定要删除这条记录吗？" icon="el-icon-info"  icon-color="red"  @onConfirm="handleDelete(scope.row.id)" >
            <el-button slot="reference" type="danger" size="small" icon="el-icon-delete" style="margin-left:5px;" >
                删除
            </el-button>
          </el-popconfirm> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="getList" />
  </div>
</template>

<script>

import { deepClone,parseTime } from '@/utils'
import * as auth from '@/utils/auth'
import * as shopApi from '@/api/shop'
import * as uploadApi from '@/api/upload'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import BxImage from '@/components/BxImage'
import guid from '@/utils/guid'
import * as imageHelper from '@/utils/image'

export default {
  name: 'TeacherInfo',
  components: { Pagination,BxImage },
  data(){
    return{
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        rows: 20,
        name:'',
        shopName:'',
      },
      search:{
        name:'',
        shopName:'',
      },
      selectOptions:{
        shop:{
          loading:false,
          remoting:false,
          data:[

          ]
        }
      }
    }
  },
  created(){
      var that=this;
      that.getList();
  },
  mounted(){

  },
  filters:{
    filterLongText(val){
      if(val && val.length>30){
        return val.substr(0,30)+"...";
      }
      return val;
    }
  },
  methods: {
    getList(){
      var that=this;
      that.listLoading = true;
      shopApi.getTeacherList(that.listQuery).then(res=>{
         if(res.data){
            that.list=[...res.data.items.map((item,index)=>{
              item._id=index+1;
              item.imageConvert=imageHelper.GetFullUrl(item.image,200,200);
              item.imageConvertLarge=[imageHelper.GetFullUrl(item.image,700,700)];
              return item;
            })];
            that.total=res.data.total || 0;
            that.listLoading = false;
         }
      })
    },
    searchClick(){
      var that=this;
      that.listQuery.page=1;
      that.listQuery.name=that.search.name.trim();
      that.listQuery.shopName=that.search.shopName.trim();
      that.getList();
    },
    handleAdd(){
      this.$router.push({ path: "/shopmanage/editteacherinfo/0" })
    },
    // handleDelete(teacherid){
    //   var that=this;

    //     shopApi.deleteTeacherInfo({id:teacherid}).then(res=>{
    //       if(res.data){
            
    //         //删除该行记录
    //         var index=that.list.findIndex(item=>item.id==teacherid);
    //         that.list.splice(index,1);

    //         that.$message({
    //           message: '删除成功',
    //           type: 'success'
    //         });
    //       }
    //     })
      
    // },
  }
}
</script>
